home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6896 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: news.smallworld.co.uk!arthur
  2. From: arthur@Smallworld.co.uk (Arthur Chance)
  3. Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
  4. Subject: Re: Access carry flag from C
  5. Date: 20 Feb 1996 14:34:03 GMT
  6. Organization: Smallworldwide
  7. Message-ID: <ARTHUR.96Feb20143404@gold.Smallworld.co.uk>
  8. References: <Dn1C9z.DGv.0.net@indra.com>
  9.     <1996Feb1922.17.19.879@koobera.math.uic.edu> <31298D20.41C6@bazis.nl>
  10. NNTP-Posting-Host: gold.smallworld.co.uk
  11. In-reply-to: Franz Korntner's message of Tue, 20 Feb 1996 08:58:08 GMT
  12.  
  13. In article <31298D20.41C6@bazis.nl> Franz Korntner <fkorntne@bazis.nl> writes:
  14. > j+k will overflow when the result exceeds MAXINT
  15. > Thus:  "if (j+k > MAXINT) overflow();" but the operation is undefined
  16. > if the result overflows, so the expression needs rewriting to make sure
  17. > this doesn't happen. The result is then "if (j>MAXINT-k) overflow();".
  18.  
  19. As we must be talking about signed ints, because unsigned can't cause
  20. undefined behaviour by overflow, if k < 0, then MAXINT-k overflows.
  21.  
  22. Basically, the C *standard* is useless on things like signed overflow
  23. (or word size, or what happens with right shift of -ve numbers, or
  24. <insert your favourite "undefined behaviour" gripe here>). You have
  25. to look carefully at each *implementation* you use. You can usually
  26. find some way to do what you want, but you have to accept it's never,
  27. ever going to be standard C.
  28.  
  29. -- 
  30. You cannot hope to bribe or twist/thank God! the British journalist.
  31. But, seeing what the man will do/unbribed, there's no occasion to. 
  32.         -- Humbert Wolfe 1886-1940
  33.